



















#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    createActions();
    createTrayIcon();

//     connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked()));
     connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
             this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));

    trayIcon->show();

    rf = new RF();
    connect( rf, SIGNAL(kWarning(QString)), this, SLOT(showMessage( QString )));

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::createActions()
{
    minimizeAction = new QAction(tr("Mi&nimize"), this);
    connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));

    maximizeAction = new QAction(tr("Ma&ximize"), this);
    connect(maximizeAction, SIGNAL(triggered()), this, SLOT(showMaximized()));

    restoreAction = new QAction(tr("&Restore"), this);
    connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));

    quitAction = new QAction(tr("&Quit"), this);
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}

void MainWindow::createTrayIcon()
{
    trayIconMenu = new QMenu(this);
    trayIconMenu->addAction(ui->actionPreferences);
    trayIconMenu->addSeparator();
    trayIconMenu->addAction(minimizeAction);
    trayIconMenu->addAction(maximizeAction);
    trayIconMenu->addAction(restoreAction);
    trayIconMenu->addSeparator();
    trayIconMenu->addAction(quitAction);

    trayIcon = new QSystemTrayIcon(this);
    trayIcon->setContextMenu(trayIconMenu);

    trayIcon->setIcon( QIcon( ":/icons/RF_Normal_Icon.png" ) );
}

 void MainWindow::setIcon(int index)
 {
/*     QIcon icon = iconComboBox->itemIcon(index);
     trayIcon->setIcon(icon);
     setWindowIcon(icon);

     trayIcon->setToolTip(iconComboBox->itemText(index));*/
 }

void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
    switch (reason) {
    case QSystemTrayIcon::Trigger:
    case QSystemTrayIcon::DoubleClick:
        break;
    case QSystemTrayIcon::MiddleClick:
        showMessage( QString ( "Elven PB near to respawn. Less than 5 minutes!!!\n\nHQ PBs near to respawn. Less than 5 minutes!!!" ));
        break;
    default:
        ;
    }
}

void MainWindow::showMessage( QString txt )
{
    trayIcon->setIcon( QIcon( ":/icons/RF_Warning_Icon.png" ) );
    trayIcon->showMessage( tr( "RF Manager - PitBoss Spawn Warning" ), txt, QSystemTrayIcon::Information );
}

void MainWindow::messageClicked()
{}

void MainWindow::on_actionPreferences_triggered()
{
    QMessageBox::warning( this, "", "MIAU" );
}
